package eerbaar.elements.extension;

import eerbaar.internal.elements.Element;
import eerbaar.internal.elements.extension.EnemyElementImpl;
import eerbaar.internal.elements.extension.EnemyElementKillerImpl;
import eerbaar.internal.elements.extension.FoodElementImpl;
import eerbaar.internal.elements.extension.LeaderElementImpl;
import eerbaar.internal.elements.extension.MovingElementImpl;
import eerbaar.internal.elements.extension.NonMovingElementImpl;
import eerbaar.internal.elements.extension.PackMemberElementImpl;
import eerbaar.internal.elements.extension.PointConsumerImpl;
import eerbaar.internal.elements.extension.PointSourceImpl;
import eerbaar.internal.elements.extension.PointsImpl;

public class ExtentionInstaller {

    public static void install(Element element) {

        final String name = element.getName();

        if ("bug".equals(name)) {

            installMovingElementImpl(element);
            installPointsImpl(element);
            installPointSourceImpl(element);
            installPointConsumerImpl(element, IPointConsumer.Priority.HIGH, 500);
            installEnemyImpl(element);
        }
        if ("pet".equals(name)) {

            installMovingElementImpl(element);
            installPointsImpl(element);
            installPointSourceImpl(element);
            installPointConsumerImpl(element, IPointConsumer.Priority.LOW, 1000);
            installPackMemberImpl(element);
        }
        if ("dog".equals(name)) {

            installMovingElementImpl(element);
            installPointsImpl(element);
            installPointSourceImpl(element);
            installPointConsumerImpl(element, IPointConsumer.Priority.LOW, 1000);
            installFriendElementImpl(element);
            installEnemyKillerImpl(element);
        }
        if (name.startsWith("bone")) {

            installNonMovingElementImpl(element);
            installFoodElementImpl(element);
            installPointsImpl(element);
            installPointSourceImpl(element);
        }
        if ("tree".equals(name)) {

            installNonMovingElementImpl(element);
        }
        if ("house".equals(name)) {

            installPointsImpl(element);
            installPointSourceImpl(element);
            installNonMovingElementImpl(element);
        }

    }

    private static void installEnemyImpl(Element result) {

        result.installExtension(IEnemyElement.class, new EnemyElementImpl(
                result));
    }

    private static void installEnemyKillerImpl(Element result) {

        result.installExtension(IEnemyElementKiller.class,
                new EnemyElementKillerImpl(result));
    }

    private static void installFoodElementImpl(Element result) {

        result.installExtension(IFoodElement.class, new FoodElementImpl(result));
    }

    private static void installFriendElementImpl(Element result) {

        result.installExtension(ILeaderElement.class, new LeaderElementImpl(
                result));
    }

    private static void installMovingElementImpl(Element result) {

        result.installExtension(IMovingElement.class, new MovingElementImpl(
                result));
    }

    private static void installNonMovingElementImpl(Element result) {

        result.installExtension(INonMovingElement.class,
                new NonMovingElementImpl(result));
    }

    private static void installPackMemberImpl(Element result) {

        result.installExtension(IPackMemberElement.class,
                new PackMemberElementImpl(result));
    }

    private static void installPointConsumerImpl(Element result,
            IPointConsumer.Priority priority, int points) {

        result.installExtension(IPointConsumer.class, new PointConsumerImpl(
                result, priority, points));
    }

    private static void installPointsImpl(Element result) {

        result.installExtension(IPoints.class, new PointsImpl(result));
    }

    private static void installPointSourceImpl(Element result) {

        result.installExtension(IPointSource.class, new PointSourceImpl(result));
    }

}
